class Solution {
public:
    void quick(vector<int>& nums, int l, int r)
    {
        if (l >= r)
        {
            return;
        }
        int a = rand();
        int key = nums[a % (r - l + 1) + l];
        int i = l;
        int left = l - 1;
        int right = r + 1;
        while (i < right)
        {
            if (nums[i] < key)
            {
                std::swap(nums[++left], nums[i++]);
            }
            else if (nums[i] == key)
            {
                i++;
            }
            else
            {
                std::swap(nums[--right], nums[i]);
            }
        }

        quick(nums, right, r);
        quick(nums, l, left);
    }

    vector<int> sortArray(vector<int>& nums) {
        srand(time(0));

        quick(nums, 0, nums.size() - 1);
        return nums;
    }
};